package com.hellpro.lolbox.home.hero;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.bean.Hero_All;
import com.hellpro.lolbox.config.UrlConfigs;

import java.util.ArrayList;
import java.util.List;

public class HeroGridAdapter extends BaseAdapter {

    private Context context;
    private List<Hero_All.AllBean> list;

    public void setData(List<Hero_All.AllBean> list) {
        this.list =list;
        notifyDataSetChanged();
    }

    public HeroGridAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();

    }

    @Override
    public int getCount() {
        return list!=null?list.size():0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView != null) {
            viewHolder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(context).inflate(R.layout.hero_all_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }
        Hero_All.AllBean allBean = list.get(position);
        String enName = allBean.getEnName();
        String cnName = allBean.getCnName();
        String path = UrlConfigs.HEROLOGO + enName + "_120x120.jpg";
        Uri parse = Uri.parse(path);
        viewHolder.logo.setImageURI(parse);
        viewHolder.mText.setText(cnName);
        return convertView;
    }



    static class ViewHolder {
         SimpleDraweeView logo;
        TextView mText;

        ViewHolder(View view) {
                logo = (SimpleDraweeView) view.findViewById(R.id.hero_logo);
            mText = (TextView) view.findViewById(R.id.hero_cnName);
        }
    }
}
